<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;

/**
 * 用于判断设备
 * 使用方法：
 * if(equipment() == 1){
 *      //手机上执行
 * }else{
 *      //PC上执行
 * }
 */
function equipment(){
    $UserAgent=$_SERVER['HTTP_USER_AGENT'];
    if(strstr($UserAgent,'Android') || strstr($UserAgent,'iPhone') || strstr($UserAgent,'iPad')){
        return 1;
    }else{
        return 0;//电脑手机都强制显示移动端样式。
    }
}
/**
 * 用于在文章详情页面post.php中获得相同分类下的上一篇和下一篇文章标题
 * 使用方法：
 * prev_post($this)
 * next_post($this)
 */
function prev_post($archive)
{
    $db = Typecho_Db::get();
    $content = $db->fetchRow($db->select()
            ->from('table.contents')
            ->where('table.contents.created < ?', $archive->created)
            ->where('table.contents.status = ?', 'publish')
            ->where('table.contents.type = ?', $archive->type)
            ->where('table.contents.password IS NULL')
            ->order('table.contents.created', Typecho_Db::SORT_DESC)
            ->limit(1));
    if ($content)
    {
        $content = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($content);
        echo '<div class="nav-previous"><a href="' . $content['permalink'] . '" rel="prev"><span class="meta-nav">上一篇： </span> <span class="post-title">' . $content['title'] . '</span></a></div>';
    }
    else
    {
        echo '上一篇：没有了';
    }
}

function next_post($archive)
{
    $db = Typecho_Db::get();
    $content = $db->fetchRow($db->select()
            ->from('table.contents')
            ->where('table.contents.created > ? AND table.contents.created < ?', $archive->created, Helper::options()->gmtTime)
            ->where('table.contents.status = ?', 'publish')
            ->where('table.contents.type = ?', $archive->type)
            ->where('table.contents.password IS NULL')
            ->order('table.contents.created', Typecho_Db::SORT_ASC)
            ->limit(1));
    if ($content)
    {
        $content = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($content);
        echo '<div class="nav-next"><a href="' . $content['permalink'] . '" rel="next"><span class="meta-nav">下一篇： </span> <span class="post-title">' . $content['title'] . '</span></a></div>';
    }
    else
    {
        echo '下一篇：没有了';
    }
}

function themeConfig($form)
{
    $logoUrl = new \Typecho\Widget\Helper\Form\Element\Text(
        'logoUrl',
        null,
        null,
        _t('站点 LOGO 地址'),
        _t('在这里填入一个图片 URL 地址, 以在网站标题前加上一个 LOGO')
    );

    $form->addInput($logoUrl);

    $sidebarBlock = new \Typecho\Widget\Helper\Form\Element\Checkbox(
        'sidebarBlock',
        [
            'ShowRecentPosts'    => _t('显示最新文章'),
            'ShowRecentComments' => _t('显示最近回复'),
            'ShowCategory'       => _t('显示分类'),
            'ShowArchive'        => _t('显示归档'),
            'ShowOther'          => _t('显示其它杂项')
        ],
        ['ShowRecentPosts', 'ShowRecentComments', 'ShowCategory', 'ShowArchive', 'ShowOther'],
        _t('侧边栏显示')
    );

    $form->addInput($sidebarBlock->multiMode());
}

/*
function themeFields($layout)
{
    $logoUrl = new \Typecho\Widget\Helper\Form\Element\Text(
        'logoUrl',
        null,
        null,
        _t('站点LOGO地址'),
        _t('在这里填入一个图片URL地址, 以在网站标题前加上一个LOGO')
    );
    $layout->addItem($logoUrl);
}
*/
function themeInit($archive) {
	if ($archive->is('category', 'daily')) {//日志
		$archive->parameter->pageSize = 5;//每页显示日志数量
	}elseif($archive->is('category', 'tech')){//技术
		$archive->parameter->pageSize = 10;//每页显示技术数量
	}elseif($archive->is('category', 'informal')){//随笔
		$archive->parameter->pageSize = 10;//每页显示随笔数量
	}elseif($archive->is('category', 'bookroom')){//书房
		$archive->parameter->pageSize = 12;//每页显示数量
	}elseif($archive->is('category', 'photo')){//相册
		$archive->parameter->pageSize = 12;//每页显示图像数量
	}elseif($archive->is('category', 'card')){//名片
		$archive->parameter->pageSize = 2;//每页显示荣誉数量
	}
}